﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ershou.BLL;
using System.IO;

public partial class gly_yhgl : System.Web.UI.Page
{
    yh yh1 = new yh();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Key"] == null)
        {
            Response.Redirect("~/Default.aspx");
        }
        if (Session["Key"].ToString() != "3")
        {
            Response.Redirect("~/Default.aspx");
        }
        if (!IsPostBack)
        {
            Bind();  //调用自定义方法Bind()
        }
    }

    protected void Bind()
    {
        var orders = yh1.GetAllOrder();
        if (orders.Count() == 0)
        {
            Panel1.Visible = false;
            lblOrder.Text = "尚无用户！";
        }
        else
        {
            Panel1.Visible = true;
            lblOrder.Text = "";
        }
        GridView1.DataSource = orders;
        GridView1.DataBind();
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Bind();  //调用自定义方法Bind()
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
            // 从行中获取数据
            string id = row.Cells[0].Text; // 假设第一列是用户ID
            yh1.Update3(int.Parse(id));
            Label1.Text = "修改成功!";
        }
        catch
        {
            Label1.Text = "修改失败!";
        }
        Bind();  //调用自定义方法Bind()
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        try
        {
            GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
            // 从行中获取数据
            string id = row.Cells[0].Text; // 假设第一列是用户ID
            yh1.Update4(int.Parse(id));
            Label1.Text = "删除成功!";
        }
        catch
        {
            Label1.Text = "删除失败!";
        }
        Bind();  //调用自定义方法Bind()
    }
}